clear
clear matrix
set mem 200000
set more off

cd ~ "INCLUDE WORKING DIRECTORY HERE"

* Combine 1972 / 1976 / 1980 files

* 1972
use anes_1972, clear

g year = 1972
g respondentid = V720002
g marijuana = V720196
g demmarijuana = V720200
g repmarijuana = V720201

g pollution = V720214
g dempollution = V720218
g reppollution = V720219

g amnesty = V720586
recode amnesty 1=0 5=1 3=. 7/9=. 0=.
recode V720587 3/5=0 8=0 9=. 0=., g(knowpartyamnesty)

g demvietnam1 = V720594
g repvietnam1 = V720595

g repvietnam2 = V720189
g demvietnam2 = V720188

for any 1 2: recode demvietnamX 9=. 0=. 
for any 1 2: recode repvietnamX 9=. 0=.


for any dem rep: egen Xvietnam = rowmax(Xvietnam1 Xvietnam2)

keep year respondentid marijuana demmarijuana repmarijuana pollution dempollution reppollution amnesty knowpartyamnesty demvietnam repvietnam
save pop_anes_1972, replace

* 1976
use anes_1976, clear

g year = 1976 
g respondentid = V763002
recode V763797 3/5=0 8=0 9=. 0=., g(knowpartyabortion)
recode V763911 1=0 5=1 8/9=. 0=., g(guncontrol)
recode V763913 8/9=. 0=. 1=0 3=.5 5=1, g(treatcriminal)
g marijuana = V763772
g demmarijuana = V763775
g repmarijuana = V763776
recode V763564 1=0 5=1 8/9=. 0=., g(carpollution)

keep year respondentid knowpartyabortion guncontrol treatcriminal marijuana demmarijuana repmarijuana carpollution
save pop_anes_1976, replace

* 1980
use anes_1980, clear

g year = 1980
g respondentid = V800004
recode V801141 8/9=. 5=1 6=.5 1=0, g(envregulations)

g demabortion = V800317
g repabortion = V800316

for any demabortion repabortion: g dkX = X == 8
for any demabortion repabortion: recode X 7=. 0=. 8/9=. 4=1 3=2 2=3 1=4
g placeabortion = repabortion - demabortion
g knowpartyabortion = 1 if inrange(placeabortion,1,3)
replace knowpartyabortion = 0 if inrange(placeabortion,-3,0)
replace knowpartyabortion = 0 if (dkrepabortion==1 | dkdemabortion==1)

keep year respondentid knowpartyabortion envregulations
save pop_anes_1980, replace

append using pop_anes_1972
append using pop_anes_1976
save pop_append_combined, replace

*******************
* Cumulative File *
*******************

use VCF0830 VCF0832 VCF0533 VCF0534 VCF0537 VCF0528 VCF0529 VCF0538 VCF9051 VCF0828 VCF0834 VCF0104 VCF0006 VCF0817 VCF0841 VCF0523 VCF0545 VCF0546 VCF0524 VCF0525 VCF0843 VCF0827a VCF0549 VCF0550 VCF0517 VCF0833 VCF0518 VCF0814 VCF0811 VCF0815 VCF0819 VCF0106 VCF0837 VCF0704 VCF0004 VCF0128a VCF0127 VCF0148a VCF0113 VCF0111 VCF0503 VCF0504 VCF0803 using anes_cdf_1948_2016, clear

g year = VCF0004
g respondentid = VCF0006

merge 1:1 year respondentid using pop_append_combined

* Demographics

recode VCF0106 2/3=0 9=. 0=., g(white)
recode VCF0106 2=1 1=0 3=0 9=. 0=., g(black)

g catholic = VCF0128a == 3
g evangelical = VCF0128a == 2

g male = VCF0104 == 1
g female = VCF0104 == 2

recode VCF0127 2=0 0=., g(union)

g workingclass = 1 if inlist(VCF0148a,1,2,3)
g middleclass = 1 if inlist(VCF0148a,4,5)
g uppermiddle = 1 if inlist(VCF0148a,6)

recode VCF0113 2=0, g(south)
recode VCF0113 2=1 1=0, g(nonsouth)

g urban = VCF0111 == 1
g suburban = VCF0111 == 2
g rural = VCF0111 == 3

* Issue Attitudes / Vote Choice

recode VCF0837 9=. 0=., g(abortion)
replace abortion = 5 - abortion
recode abortion 1/2=0 3/4=1, g(abortion01)

recode VCF0704 0=. 3=. 2=1 1=0, g(voterep)
recode VCF0704 0=. 3=. 2=0 1=1, g(votedem)

g ideology = VCF0803
g busing = VCF0817
g unrest = VCF0811
g aidblack = VCF0830
g women = VCF0834
g accuse = VCF0832
g vietnam = VCF0827a
g defense8016 = VCF0843
g russia = VCF0841

for any ideology busing unrest aidblack women accuse vietnam defense8016 russia marijuana pollution: recode X 0=. 8/9=.

recode VCF0815 0=. 9=. 1=0 2=.5 3=1, g(segregation) // 3 options
recode VCF0819 0=. 9=. 2=0, g(housing) // 2 options
recode VCF0814 0=. 9=. 1=0 2=.5 3=1, g(civilrtsmove) // 3 options
recode VCF0833 0=. 9=. 8=. 1=0 5=1, g(era) // 2 options
recode VCF0828 1=0 2=1 9=. 0=., g(defense7276) // 2 options
recode VCF9051 5=0 8=. 9=., g(prayer) // 2 options

* Party positions

g demideology = VCF0503
g repideology = VCF0504

g demaidblack = VCF0517
g repaidblack = VCF0518

g demdefense = VCF0549
g repdefense = VCF0550

g demaccuse = VCF0524
g repaccuse = VCF0525

g demrussia = VCF0545
g reprussia = VCF0546

g dembusing = VCF0533
g repbusing = VCF0534

g demwomen = VCF0537
g repwomen = VCF0538

g demunrest = VCF0528
g repunrest = VCF0529

recode VCF0523 2/3=0 8=0 0=., g(knowpartydefense7276)

foreach x in dem rep{

for any ideology aidblack defense accuse russia busing women unrest marijuana pollution vietnam: g dk`x'X = `x'X == 8
for any ideology aidblack defense accuse russia busing women unrest marijuana pollution vietnam: recode `x'X 0=. 8/9=.

}

for any ideology aidblack defense accuse russia busing women unrest marijuana pollution vietnam: g knowpartyX = 0 if (dkdemX == 1 | dkrepX==1)
for any ideology aidblack defense accuse russia busing women unrest marijuana pollution vietnam: g placeX = repX - demX
for any ideology aidblack defense accuse russia busing women unrest marijuana pollution vietnam: replace knowpartyX = 1 if inrange(placeX,1,6)
for any ideology aidblack defense accuse russia busing women unrest marijuana pollution vietnam: replace knowpartyX = 0 if inrange(placeX,-6,0)

rename knowpartydefense knowpartydefense8016
egen knowpartydefense = rowmax(knowpartydefense7276 knowpartydefense8016)

save pop_anes_datafile, replace


* FIGURE 1

use pop_anes_datafile, clear

preserve
clear 
set obs 1
g holder = .
save pop_fig1, replace
save pop_fig1_white, replace
restore

* Make 0/1
for any ideology busing unrest aidblack women accuse vietnam defense8016 russia marijuana pollution: recode X 1/3=0 4=.5 5/7=1
egen defense = rowmax(defense8016 defense7276)
for any segregation civilrtsmove envregulations carpollution treatcriminal: recode X .5=.
for any ideology segregation housing civilrtsmove aidblack busing marijuana accuse unrest women pollution amnesty defense vietnam guncontrol treatcriminal era carpollution prayer envregulations russia: recode X .5=.
for any ideology segregation housing civilrtsmove aidblack busing marijuana accuse unrest women pollution amnesty defense vietnam guncontrol treatcriminal era carpollution prayer envregulations russia: tab X

foreach x in ideology segregation housing civilrtsmove aidblack busing marijuana accuse unrest women pollution amnesty defense vietnam guncontrol treatcriminal era carpollution prayer envregulations russia {
levelsof year if abortion01!=. & `x'!=. & inlist(year,1972,1976,1980), local(levels)
foreach l of local levels{


reg abortion01 `x' if year==`l'
preserve
regsave, ci
keep if var=="`x'"
g year = `l'
append using pop_fig1
save pop_fig1, replace
restore

reg abortion01 `x' if year==`l' & white==1
preserve
regsave, ci
keep if var=="`x'"
g year = `l'
append using pop_fig1_white
save pop_fig1_white, replace
restore


}
}


* FIGURE 2

use pop_anes_datafile, replace

* ANES 1972
for any white black: sum abortion01 if X==1
for any catholic evangelical union uppermiddle middleclass workingclass nonsouth south male female: sum abortion01 if X==1
for any urban suburban rural: sum abortion01 if X==1 & white==1 & south==1
for any urban suburban rural: sum abortion01 if X==1 & white==1 & nonsouth==1

* GALLUP 1969

use gallup_nov_1969, clear

g north = 1 if south!=1

g southrural = 1 if south==1 & rural==1
g southurban = 1 if south==1 & rural==0
g northrural = 1 if north==1 & rural==1
g northurban = 1 if north==1 & rural==0

g northwhite = 1 if white==1 & north==1
g southwhite = 1 if white==1 & south==1

g whitecatholic = 1 if white==1 & catholic==1
g whitesouthbaptist = 1 if south==1 & white==1 & baptist==1

g female = 1 if male ==0

g w_male = 1 if male==1 & white==1
g w_female = 1 if male==0 & white==1

for any whitesouthbaptist white black northrural  northurban southrural  southurban  whitecatholic northwhite southwhite w_male w_female: sum abortion if X==1


* FIGURE 3

use pop_anes_datafile, clear

egen rep_abortion = mean(abortion) if voterep==1, by(year)
egen dem_abortion = mean(abortion) if votedem==1, by(year)

for any black white: egen rep_abortion_X = mean(abortion) if voterep==1 & X==1, by(year)
for any black white: egen dem_abortion_X = mean(abortion) if votedem==1 & X==1, by(year)

table year, c(mean rep_abortion mean dem_abortion)
table year, c(mean rep_abortion_white mean dem_abortion_white)
table year, c(mean rep_abortion_black mean dem_abortion_black)

* FIGURE 4

use harris_may_1969, clear

preserve
clear
set obs 1
g holder = .
save abortionbundles_pre1972, replace
restore

foreach x in gunpermit homosexual banporn marijuanamoral rightsaccuse{

reg abortionchoice `x'
preserve
regsave, ci
keep if var=="`x'"
g firm="harris"
g date="may1969"
append using abortionbundles_pre1972
save abortionbundles_pre1972, replace
restore

}

use harris_aug_1970, clear

foreach x in womenstatus pollution studentprotest womenpolitics{

reg abortion1 `x' [pweight=weight]
preserve
regsave, ci
keep if var=="`x'"
g firm="harris"
g date="august1970"
append using abortionbundles_pre1972
save abortionbundles_pre1972, replace
restore

}

use abortionbundles_pre1972, clear

g index = 1 if var=="womenstatus"
replace index = 2 if var=="womenpolitics"
replace index = 3 if var=="pollution"
replace index = 4 if var=="studentprotest"
replace index = 5 if var=="gunpermit"
replace index = 6 if var=="homosexual"
replace index = 7 if var=="banporn"
replace index = 8 if var=="marijuanamoral"

save abortionbundles_pre1972, replace



* FIGURE 5

use pop_anes_datafile, clear

* Vote Republican
egen voterep_all = mean(voterep), by(year)
egen voterep_white = mean(voterep) if white==1, by(year)
egen voterep_evangelical = mean(voterep) if white==1 & evangelical==1, by(year)

table year, c(mean voterep_all mean voterep_white mean voterep_evangelical)

* Issue Positions
for any ideology segregation housing civilrtsmove aidblack busing marijuana accuse unrest women pollution amnesty defense vietnam abortion: center X if year==1972, inplace standardize
for any ideology segregation housing civilrtsmove aidblack busing marijuana accuse unrest women pollution amnesty defense vietnam abortion: reg X evangelical if white==1 & year ==1972


* Table 1

use pop_anes_datafile, clear
set more off

* Make 0/1
for any ideology busing unrest aidblack women accuse vietnam defense8016 russia marijuana pollution: recode X 1/3=0 4=.5 5/7=1
egen defense = rowmax(defense8016 defense7276)
for any segregation civilrtsmove envregulations carpollution treatcriminal: recode X .5=.
for any ideology segregation housing civilrtsmove aidblack busing marijuana accuse unrest women pollution amnesty defense vietnam guncontrol treatcriminal era carpollution prayer envregulations russia: recode X .5=.
for any ideology segregation housing civilrtsmove aidblack busing marijuana accuse unrest women pollution amnesty defense vietnam guncontrol treatcriminal era carpollution prayer envregulations russia: tab X


forvalues i = 0/1 {
foreach x in ideology aidblack busing marijuana accuse unrest women pollution amnesty defense vietnam  russia {

levelsof year if abortion01!=. & `x'!=. & knowpartyabortion!=. & knowparty`x'!=. & inlist(year,1976,1980), local(levels)
foreach l of local levels{

reg abortion01 `x' if year==`l' & knowpartyabortion==`i' & knowparty`x'==`i' & white==1

}
}
}


foreach x in ideology aidblack busing marijuana accuse unrest women pollution amnesty defense vietnam  russia {

levelsof year if abortion01!=. & `x'!=. & knowparty`x'!=. & inlist(year,1972,1976,1980), local(levels)
foreach l of local levels{

reg abortion01 `x' if year==`l' & knowparty`x'==0 & white==1

}
}



